import request from './request';

export function fetchTravelData(ProjectId,date) {
  return request({
    url: `/travel/getlist?projectId=${ProjectId}&time=${date}`,
    method: 'get',
  });
}
export function addTravelRecord(data) {
  return request({
    url: `/travel/save`,
    method: 'post',
    data: data
  });
}
export function uploadVoucher(filePath) {
  return new Promise((resolve, reject) => {
    wx.uploadFile({
      url: 'https://jiamuyuanxun.cn/common/upload',
      // url: 'http://localhost:8081/common/upload',
      filePath: filePath,
      name: 'file',
      success: res => {
        try {
          const data = JSON.parse(res.data);
          if (data.code === 1) {
            resolve(data); // 返回上传成功后的数据
          } else {
            reject(data);
          }
        } catch (e) {
          console.error('Error parsing response:', res.data);
          reject(e);
        }
      },
      fail: err => {
        reject(err);
      }
    });
  });
}
export function getImage(imageName) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: 'https://jiamuyuanxun.cn/common/image',
      // url: 'http://localhost:8081/common/image',
      
      method: 'GET',
      // responseType: 'arraybuffer', // 获取二进制数据
      data: {
        imagePath: imageName
      },
      success: res => {
        resolve(res);
      },
      fail: err => {
        reject(err);
      }
    });
  });
}